home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / library / src / sumlibrary.c < prev   
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.4 KB  |  113 lines

  1. /*
  2.     (C) 1995, 96 AROS - The Amiga Replacement OS
  3.     $Id$
  4.     $Log$
  5.     Desc:
  6.     Lang: english
  7. */
  8. #include "exec_intern.h"
  9. #include <exec/execbase.h>
  10. #include <exec/alerts.h>
  11. #include <aros/libcall.h>
  12.  
  13. /*****************************************************************************
  14.  
  15.     NAME */
  16.     #include <clib/exec_protos.h>
  17.  
  18.     __AROS_LH1(void, SumLibrary,
  19.  
  20. /*  SYNOPSIS */
  21.     __AROS_LA(struct Library *, library,A1),
  22.  
  23. /*  LOCATION */
  24.     struct ExecBase *, SysBase, 71, Exec)
  25.  
  26. /*  FUNCTION
  27.     Builds the checksum over a given library's jumptable and either puts
  28.     it into the library->lib_Sum field (if the library is marked as changed)
  29.     or compares it with this field and Alert()s at mismatch.
  30.  
  31.     INPUTS
  32.     library - Pointer to library structure.
  33.  
  34.     RESULT
  35.  
  36.     NOTES
  37.  
  38.     EXAMPLE
  39.  
  40.     BUGS
  41.  
  42.     SEE ALSO
  43.     AddLibrary(), RemLibrary(), MakeLibrary(), MakeFunctions(), InitStruct().
  44.  
  45.     INTERNALS
  46.  
  47.     HISTORY
  48.  
  49. ******************************************************************************/
  50. {
  51.     __AROS_FUNC_INIT
  52.  
  53.     UBYTE oldflags;
  54.     ULONG sum;
  55.  
  56.     /* Arbitrate for library base */
  57.     Forbid();
  58.  
  59.     /*
  60.     If the library checksumming is already in progress or if the
  61.     checksum is unused skip this part
  62.     */
  63.     if(library->lib_Flags&LIBF_SUMUSED&&!(library->lib_Flags&LIBF_SUMMING))
  64.     {
  65.     /* As long as the library is marked as changed */
  66.     do
  67.     {
  68.         ULONG *lp;
  69.  
  70.         /* Memorize library flags */
  71.         oldflags=library->lib_Flags;
  72.  
  73.         /* Tell other tasks: Summing in progress */
  74.         library->lib_Flags|=LIBF_SUMMING;
  75.         library->lib_Flags&=~LIBF_CHANGED;
  76.  
  77.         /* As long as the summing goes multitasking may be permitted. */
  78.         Permit();
  79.  
  80.         /* Build checksum. Note: library bases are LONG aligned */
  81.         sum=0;
  82.         /* Get start of jumptable */
  83.         lp=(ULONG *)((UBYTE *)library+library->lib_NegSize);
  84.         /* And sum it up */
  85.         while(lp<(ULONG *)library)
  86.         sum+=*lp++;
  87.  
  88.         /* Summing complete. Arbitrate again. */
  89.         Forbid();
  90.  
  91.         /* Remove summing flag */
  92.         library->lib_Flags&=~LIBF_SUMMING;
  93.  
  94.         /* Do it again if the library changed while summing. */
  95.     }while(library->lib_Flags&LIBF_CHANGED);
  96.  
  97.     /*
  98.         Alert() if the library wasn't marked as changed and if the
  99.         checksum mismatches.
  100.     */
  101.     if(!(oldflags&LIBF_CHANGED)&&library->lib_Sum!=sum)
  102.         Alert(AT_DeadEnd|AN_LibChkSum);
  103.  
  104.     /* Set new checksum */
  105.     library->lib_Sum=sum;
  106.     }
  107.  
  108.     /* All done. */
  109.     Permit();
  110.     __AROS_FUNC_EXIT
  111. } /* SumLibrary */
  112.  
  113.